<?php
namespace Modules\Skinov\Controllers;

use Endroid\QrCode\QrCode;

class QRCodeController extends ControllerBase {
  public function wechatRecommendAction() {
    $easyWeChatConfig = $this -> easyWeChat -> getConfig();
    $callbackUrl = urlencode($this -> config -> BASE_URL.'/skinov/callback/redirectRecommend?target_url=user&pid='.$this -> request -> getQuery('id', 'int', 0, true));
    $redirectUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$easyWeChatConfig['app_id'].'&redirect_uri='.$callbackUrl.'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';

    $qrCode = new QrCode($redirectUrl);
    $qrCode -> setWriterByName('png');

    return $this -> response -> setContentType($qrCode -> getContentType()) -> setContent($qrCode -> writeString());
  }
}
